package com.tiancheng.trade.commom.web.auth;

import com.tiancheng.admintoken.constant.AuthConstant;
import com.tiancheng.admintoken.dto.UserDto;
import com.tiancheng.admintoken.utils.StpKit;
import com.tiancheng.trade.commom.core.exception.Asserts;
import lombok.extern.slf4j.Slf4j;

/**
 * 用户令牌工具类
 */
@Slf4j
public class AuthSubjectUtils {

    /**
     * 获取登录用户
     *
     * @return
     */
    public static UserDto getLoginUser() {
        if (StpKit.PLATFORM.isLogin()) {
            return (UserDto) StpKit.PLATFORM.getSession().get(AuthConstant.ADMIN_INFO);
        }
        if (StpKit.MERCHANT.isLogin()) {
            return (UserDto) StpKit.MERCHANT.getSession().get(AuthConstant.ADMIN_INFO);
        }
        if (StpKit.CONSUMER.isLogin()) {
            return (UserDto) StpKit.CONSUMER.getSession().get(AuthConstant.CONSUMER_INFO);
        }
        Asserts.fail("当前用户未登录！");
        return null;
    }

}
